<%@page contentType="text/html; charset=UTF-8" session="false" %>
<%@include  file="/WEB-INF/jspf/import.jspf"%>
<div class="pageHeader">
    <form  onsubmit="return navTabSearch(this);" pagerFormId="dynaList" id="pagerForm" name="searchForm" method="get">
        <input type="hidden" name="pageNum" value="${pager.pageNo}" />
        <input type="hidden" name="pageSize" value="${pager.pageSize}" />
        <div class="searchBar">
            <table class="searchContent">
                <tbody>
                    <tr>
                        <td colspan="2"><label>发布时间：</label>
                            <input type="text" value="${from}" id="dyna_publish_from" name="from" datefmt="yyyy-MM-dd 00:00:00" class="date" readonly="true">至
                            <input type="text" value="${to}" id="dyna_publish_to" name="to" datefmt="yyyy-MM-dd 23:59:59" class="date" readonly="true">
                        </td>
                        <td><label>关键字：</label><input type="text" name="keyword"  value="${param.keyword}" class="textInput"></td>
                    </tr>
                </tbody>
            </table>
            <div class="subBar">
                <ul>
                    <li><div class="buttonActive"><div class="buttonContent"><button type="button" onclick="exportFile();">导出Excel</button></div></div></li>
                    <li><div class="buttonActive"><div class="buttonContent"><button type="submit">查询</button></div></div></li>
                </ul>
            </div>
        </div>
    </form>
</div>
<div class="pageContent">
    <table class="table" style="width: 100%" layoutH="110">
        <thead>
            <tr>
                <th orderField="dynaInfoId">动态id</th>
                <th>车友会id</th>
                <th>内容</th>
                <th>回复时间</th>
                <th>回复数</th>
                <th>点赞(时段/总数)</th>
                <th>发表时间</th>
                <th>发表人</th>
                <th>更新时间</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach var="entity" items="${pager.resultList}">
                <tr target="dynaInfoId" rel="${geli:oid(entity)}">
                    <td>${geli:display(entity,'dynaInfoId')}</td>
                    <td>${geli:display(entity,'clubId')}</td>
                    <td><a href="${UCROOT}/${entity.createBy}/dt/${geli:oid(entity)}" target="_blank"><c:if test="${empty entity.content and entity.isPic==1}">[图]</c:if>${fn:substring(entity.content,0,100)}</a></td>
                    <td>${geli:display(entity,'lastPostAt')}</td>
                    <td>${geli:display(entity,'postCount')}</td>
                    <td>${empty termPraise[entity.dynaInfoId]?0:termPraise[entity.dynaInfoId]}/${geli:display(entity,'praiseCount')}</td>
                    <td>${geli:display(entity,'createDate')}</td>
                    <td>${fn:escapeXml(entity.createName)}(${geli:display(entity,'createBy')})</td>
                    <td>${geli:display(entity,'updateAt')}</td>
                </tr>
            </c:forEach>
        </tbody>
    </table>

    <div class="panelBar">
        <div class="pages">
            <span>共 ${pager.total} 条</span>
        </div>
        <div class="pagination" targetType="navTab" totalCount="${pager.total}" numPerPage="${pager.pageSize}" pageNumShown="10" currentPage="${pager.pageNo}"></div>
    </div>
</div>
<script>
    $(function() {
        var now = new Date();
        var dayMillis = 1000*60*60*24;
        var lastDay = new Date(now - dayMillis),
        lastWeekDay =  new Date(now - dayMillis*7);
        if(!$("#dyna_publish_from").val() && !$("#dyna_publish_to").val()) {
            $("#dyna_publish_from").val(now.formatDate("yyyy-MM-dd"));
            $("#dyna_publish_to").val(now.formatDate("yyyy-MM-dd"));
        }
        $("#dyna_publish_from").focus(function() {
            var $this = $(this);
            var minDate = "2000-01-01";
            var maxDate = $("#dyna_publish_to").val() || "{%y}-%M-{%d}";
            var opts = {
                maxDate : maxDate
            };
            $this.datepicker(opts);
        });
        $("#dyna_publish_to").focus(function() {
            var $this = $(this);
            var minDate = $("#dyna_publish_from").val() || "2000-01-01";
            var opts = {
                minDate : minDate
            };
            $this.datepicker(opts);
        });
    });

    function exportFile(){
        var data =$("#pagerForm[pagerFormId=dynaList]").serializeArray();
        var params = new Array();
        var beginDate = $("#dyna_publish_from").val();
        var endDate =  $("#dyna_publish_to").val();
        var days = better_time(beginDate,endDate);
        if(days > 31){
        	alert("所选时间段不能超过一个月");
        	return;
        }
        for(var i in data) {
            params.push(data[i].name+'='+encodeURIComponent(data[i].value));
        }
        var queryString = params.join('&')
	
        location.href = "/admin/dyna/batchExport.do?"+queryString;
	
    }
    
    function better_time(strDateStart,strDateEnd){
    	   var strSeparator = "-"; //日期分隔符
    	   var strDateArrayStart;
    	   var strDateArrayEnd;
    	   var intDay;
    	   strDateArrayStart = strDateStart.split(strSeparator);
    	   strDateArrayEnd = strDateEnd.split(strSeparator);
    	   var strDateS = new Date(strDateArrayStart[0] + "/" + strDateArrayStart[1] + "/" + strDateArrayStart[2]);
    	   var strDateE = new Date(strDateArrayEnd[0] + "/" + strDateArrayEnd[1] + "/" + strDateArrayEnd[2]);
    	   intDay = (strDateE-strDateS)/(1000*3600*24);
    	   return intDay;
    	}
</script>